﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorldBankBBS.Logic;
using WorldBankBBS.Pathing;

namespace WorldBankBBS.EMail
{
    public class EMailPathHandler : IPathHandler
    {
        public Session Session { get; private set; }
        private EMailEvents _events = null;

        public EMailPathHandler(Session session)
        {
            Session = session;
            _events = BbsDispatcher.GetDispatcher(session).GetObject <EMailEvents> (typeof(EMailEvents).FullName);
        }

        public void ProcessPath(string path)
        {
            var parts = path.Split(new[] {'|'});

            switch (parts[0].ToLower())
            {
                case "listemails":
                    _events.InvokeListEmails();
                    break;
                case "createemail":
                    _events.InvokePreCreateEmail();
                    if (parts.Length == 2)
                    {
                        _events.InvokeCreateEmail(Guid.Parse(parts[1]));
                    }
                    else
                    {
                        _events.InvokeCreateEmail(Guid.Empty);
                    }
                    _events.InvokePostCreateEmail();
                    break;
                case "reademail":
                    _events.InvokeReadEmail(Guid.Parse(parts[1]));
                    _events.InvokePostEmailRead();
                    break;
                case "deleteemail":
                    _events.InvokePreDeleteEmail();
                    _events.InvokeDeleteEmail(Guid.Parse(parts[1]));
                    _events.InvokePostDeleteEmail();
                    break;
                case "enteremailsection":
                    _events.InvokeEnterEmailSection();
                    break;
            }
        }
    }
}
